package com.julis.activity.main.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.Constant;
import com.baseutils.SpfUtils;
import com.julis.R;
import com.julis.activity.check.N_Car_OBU2_Activity;
import com.julis.activity.check.N_Car_VIN1_Activity;
import com.julis.activity.check.N_QRSBXX3_Activity;
import com.thread.OffLineThread;
import com.xyz.step.FlowViewHorizontal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * 首页
 */
public class Home_Fragment extends Fragment {
    View view;


    //    @BindView(R.id.name)
//    TextView name;
    @BindView(R.id.textView7)
    TextView textView7;
    @BindView(R.id.textView6)
    TextView textView6;
    @BindView(R.id.textView20)
    TextView textView20;
    @BindView(R.id.button)
    Button button;
    @BindView(R.id.hflowview4)
    FlowViewHorizontal hFlow4;
    List<String> ccList = new ArrayList<String>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = View.inflate(getActivity(), R.layout.fragment_sy, null);
            ButterKnife.bind(this, view);

            if (Constant.Manufacturer == 0) {
                Constant.ManufacturerName="检测";
            } else {
                Constant.ManufacturerName="交易";
            }
        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }


        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        ccList.clear();
        boolean Check_Vin = (boolean) SpfUtils.get(getActivity(), Constant.Check_Vin, true);
        boolean Inpue_Obu = (boolean) SpfUtils.get(getActivity(), Constant.Inpue_Obu, true);
        boolean Bluetooth_Check = (boolean) SpfUtils.get(getActivity(), Constant.Check_Bluetooth, true);
        boolean Check_kl15 = (boolean) SpfUtils.get(getActivity(), Constant.Check_kl15, true);
        if (Check_Vin) {
            ccList.add("录入VIN号");
        }
        if (Inpue_Obu) {
            ccList.add("录入OBU");
        }
        if (Check_kl15) {
            ccList.add("OBU自检");
        }
        if (Bluetooth_Check) {
            ccList.add("蓝牙检测");
        }
        String data =Constant.ManufacturerName;
        ccList.add(data);

        if (Check_Vin) {
            ccList.add("写入VIN号");
        }
        String[] objects = (String[]) ccList.toArray(new String[ccList.size()]);
//        Map<String, String> map = new HashMap<>();
//        map.put("异常", "#FF0000");
        hFlow4.setProgress(ccList.size(), ccList.size(), objects, null);
//        hFlow4.setKeyColor(map);
    }

    @OnClick({R.id.button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
//            case R.id.setting:
//                String name = (String) SpfUtils.get(getActivity(), "name", "");
//                if (!name.equals("admin")) {
//                    startActivity(new Intent(getActivity(), Setting2_Activity.class));
//                }else{
//                    startActivity(new Intent(getActivity(), Setting_Activity.class));
//                }


//                break;
            case R.id.button:
                OffLineThread setParam = new OffLineThread("A9_2", getActivity());
                setParam.start();
                SpfUtils.put(getActivity(), Constant.VIN_Code, "");
                SpfUtils.put(getActivity(), Constant.OBU_Code, "");
                SpfUtils.put(getActivity(), Constant.VIN_InputTime, "");
                SpfUtils.put(getActivity(), Constant.OBU_InputTime, "");
                SpfUtils.put(getActivity(), Constant.VIN_InputSucess, "");
                SpfUtils.put(getActivity(), Constant.OBU_InputSucess, "");
                SpfUtils.put(getActivity(), Constant.OBU_TradeSucess, "");
                SpfUtils.put(getActivity(), Constant.OBU_CheckTime, "");
                boolean Check_Vin = (boolean) SpfUtils.get(getActivity(), Constant.Check_Vin, true);
                boolean Inpue_Obu = (boolean) SpfUtils.get(getActivity(), Constant.Inpue_Obu, true);

                if (Check_Vin || Inpue_Obu) {
                    if (Check_Vin) {
                        startActivity(new Intent(getActivity(), N_Car_VIN1_Activity.class));
                    } else {
                        startActivity(new Intent(getActivity(), N_Car_OBU2_Activity.class));
                    }
                } else {
                    startActivity(new Intent(getActivity(), N_QRSBXX3_Activity.class));
                }


                break;

        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();


    }
}
